package com.ycxy.school.express.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ycxy.school.express.pojo.dto.AddressAddNewDTO;
import com.ycxy.school.express.pojo.dto.AddressUpdateDTO;
import com.ycxy.school.express.pojo.dto.OrderEvaluateAddNewDTO;
import com.ycxy.school.express.pojo.entity.OrderEvaluate;
import com.ycxy.school.express.pojo.vo.OrderEvaluateListItemVO;
import com.ycxy.school.express.pojo.vo.OrderListItemVO;
import com.ycxy.school.express.service.IOrderEvaluateService;
import com.ycxy.school.express.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author jayLuo
 * @Date 2023/1/12 15:13
 * @PackageName:com.ycxy.school.express.controller
 * @ClassName: OrderEvaluateController
 * @Description: TODO
 * @Version 1.0
 */
@Slf4j
@Api(tags = "08. 订单评价管理模块")
@RestController
@RequestMapping("/evaluates")
public class OrderEvaluateController {

    @Autowired
    private IOrderEvaluateService orderEvaluateService;

    // http://localhost:9080/evaluates/add-new
    @ApiOperation("添加订单评价数据")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(
            OrderEvaluateAddNewDTO orderEvaluateAddNewDTO,
            Long staffId,Long orderId) {
        log.debug("开始处理【添加订单评价数据】的请求，参数：{}", orderEvaluateAddNewDTO);
        orderEvaluateService.addNew(orderEvaluateAddNewDTO,staffId,orderId);
        return JsonResult.ok();
    }

    // http://localhost:9080/evaluates/9527/delete
    @ApiOperation("根据id删除订单评价数据")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "订单评价数据id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@Range(min = 1, message = "删除订单评价数据失败，尝试删除的数据ID无效！")
                                   @PathVariable Long id) {
        log.debug("开始处理【根据id删除订单评价数据】的请求，参数：{}", id);
        orderEvaluateService.delete(id);
        return JsonResult.ok();
    }


    // http://localhost:9080/evaluates/9527/add-message
    @ApiOperation("根据id追加评价")
    @ApiOperationSupport(order = 310)
    @ApiImplicitParam(name = "id", value = "订单评价数据id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/add-message")
    public JsonResult<Void> updateById(@PathVariable Long id, String addMessage) {
        log.debug("开始处理【追加评价】的请求，参数ID：{}, 新数据：{}", id, addMessage);
        orderEvaluateService.addMessage(id, addMessage);
        return JsonResult.ok();
    }

    // http://localhost:9080/evaluates/user
    @ApiOperation("根据用户id查询订单评价列表")
    @ApiOperationSupport(order = 410)
    @GetMapping("/user")
    public JsonResult<List<OrderEvaluateListItemVO>> listByUserId() {
        log.debug("开始处理【根据用户id查询订单列表】的请求");
        List<OrderEvaluateListItemVO> list = orderEvaluateService.listByUserId();
        return JsonResult.ok(list);
    }

    // http://localhost:9080/evaluates/staff
    @ApiOperation("根据骑手id查询订单评价列表")
    @ApiOperationSupport(order = 420)
    @GetMapping("/staff")
    public JsonResult<List<OrderEvaluateListItemVO>> listByStaffId() {
        log.debug("开始处理【根据骑手id查询订单评价列表】的请求");
        List<OrderEvaluateListItemVO> list = orderEvaluateService.listByStaffId();
        return JsonResult.ok(list);
    }
}
